package com.example.pufang.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.common.CommonResult;
import com.example.common.PageParamRequest;
import com.example.pufang.pojo.Report;
import com.example.pufang.service.ReportService;
import com.example.pufang.vo.PageListVo;
import com.example.pufang.vo.ReportAdminDetailVo;
import com.example.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/report")
@CrossOrigin
@Api(tags = "web举报日志接口")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @Autowired
    private TokenUtil tokenUtil;

    @Operation(summary = "获取分页用户列表")
    @GetMapping("/getListByPage")
    public CommonResult<PageListVo> getListByPage(PageParamRequest pageParamRequest, String searchName, String searchReason) {
        return CommonResult.success(reportService.getListByPage(pageParamRequest, searchName, searchReason));
    }

    @Operation(summary = "获取分页用户列表")
    @GetMapping("/getDeail")
    public CommonResult<ReportAdminDetailVo> getDetail(String reportId) {

        if (StringUtils.isBlank(reportId)) {
            return CommonResult.failed("获取失败");
        }

        return CommonResult.success(reportService.getDetail(reportId));
    }

    @Operation(summary = "通过举报")
    @PostMapping("/passReport")
    public CommonResult<Boolean> passReport(@RequestBody Report report, HttpServletRequest request) {

        Integer adminId = tokenUtil.getAdminId(request);

        if (StringUtils.isBlank(report.getId())) {
            return CommonResult.failed("获取失败");
        }

        return CommonResult.success(reportService.passReport(report.getId(), adminId));
    }

    @Operation(summary = "拒绝举报")
    @PostMapping("/refuseReport")
    public CommonResult<Boolean> refuseReport(@RequestBody Report report, HttpServletRequest request) {

        Integer adminId = tokenUtil.getAdminId(request);

        if (StringUtils.isBlank(report.getId())) {
            return CommonResult.failed("获取失败");
        }

        return CommonResult.success(reportService.refuseReport(report.getId(), adminId));
    }

}
